package com.stylefeng.guns.modular.vpn_pay_method.service.impl;

import com.stylefeng.guns.core.common.constant.DatasourceEnum;
import com.stylefeng.guns.core.mutidatasource.annotion.DataSource;
import com.stylefeng.guns.modular.system.model.Paymethod;
import com.stylefeng.guns.modular.system.dao.PaymethodMapper;
import com.stylefeng.guns.modular.vpn.dto.PayMethodDTO;
import com.stylefeng.guns.modular.vpn.utils.LogUtil;
import com.stylefeng.guns.modular.vpn_pay_method.service.IPaymethodService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2020-03-26
 */
@Service
public class PaymethodServiceImpl extends ServiceImpl<PaymethodMapper, Paymethod> implements IPaymethodService {

    @Override
    @DataSource(name = DatasourceEnum.DATA_SOURCE_BIZ)
    public void addPayMethod(PayMethodDTO dto) {
        Paymethod  paymethod = new Paymethod();
        paymethod.setStatus(dto.getStatus());
        paymethod.setPlatform(dto.getPlatform());
        paymethod.setPaymentId(dto.getPaymentId());

        String platformName = "";
        if (paymethod.getPlatform() == 1){
            platformName = "Android";
        }else if(paymethod.getPlatform() == 2){
            platformName = "IOS";
        }else if(paymethod.getPlatform() == 3){
            platformName = "Windows";
        }else if(paymethod.getPlatform() == 4){
            platformName = "Mac";
        }else if(paymethod.getPlatform() == 5){
            platformName = "Web";
        }

        if (dto.getPaymentId() == 1){
            paymethod.setIcon("icon_zfb.png");
            paymethod.setPaymentName("支付宝");
            paymethod.setEnglishName("ALIPAY");
            paymethod.setTaiwanName("支付寶");
        }else if (dto.getPaymentId() == 2){
            paymethod.setIcon("icon_wx.png");
            paymethod.setPaymentName("微信支付");
            paymethod.setEnglishName("WECHATONL");
            paymethod.setTaiwanName("微信支付");
        }else if (dto.getPaymentId() == 3){
            paymethod.setIcon("icon_yl.png");
            paymethod.setPaymentName("中国银联");
            paymethod.setEnglishName("CHINAPAY");
            paymethod.setTaiwanName("中國銀聯");
        }else  if (dto.getPaymentId() == 6){
            paymethod.setIcon("inapp.png");
            paymethod.setPaymentName("苹果内购");
            paymethod.setEnglishName("INAPP");
            paymethod.setTaiwanName("蘋果內購");
        }else  if (dto.getPaymentId() == 8){
            paymethod.setPaymentName("VIP手动添加");
            paymethod.setEnglishName("VIP");
            paymethod.setTaiwanName("VIP手动添加");
        }

        super.baseMapper.insert(paymethod);

        LogUtil.saveOperationLog("添加支付方式",
                "添加平台"+platformName+", "+paymethod.getPaymentName()+"支付方式");

    }
}
